package com.nj.api.web.config;

import com.nj.api.web.interceptor.LoginInterceptor;
import com.nj.api.web.interceptor.ResetLoginTimeout;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;

@Configuration
//配置拦截器
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;
    @Resource
    private ResetLoginTimeout resetLoginTimeout;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        resetLoginTimeout(registry);
        isLogin(registry);

    }

    private void isLogin(InterceptorRegistry registry) {
        ArrayList<String> paths = new ArrayList<>();
        paths.add("/bid/investment");
        paths.add("/account/getBalance");
        registry.addInterceptor(loginInterceptor).addPathPatterns(paths);
    }

    private void resetLoginTimeout(InterceptorRegistry registry) {
        registry.addInterceptor(resetLoginTimeout).addPathPatterns("/**");
    }
}
